package com.voxel.sense.infomsg.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.com.common.utils.PhoneUtils;
import com.example.com.common.utils.SizeUtils;
import com.example.com.common.utils.ToastUtil;
import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;

import org.w3c.dom.Text;

import cyy.example.com.facotry.Factory;
import cyy.example.com.facotry.constants.Constants;
import cyy.example.com.facotry.model.api.response.TaskDetailsInfoEntity;

public class MapStaffInfoTaskWindow extends BottomSheetDialog {

  private RecyclerAdapter mAdapter;
  private TextView task_name;

  private TextView task_desc;//用户岗位

  private RecyclerView recycle_view;
  private final TextView taskNum;
  private final TextView taskType;
  private final TextView taskLevel;
  private final TextView taskPerson;
  private final TextView taskStatue;
  private final TextView taskTime;

  public MapStaffInfoTaskWindow(@NonNull Context context) {
    super(context, 0);
    //        super(context, R.style.MyDialog);
    //设置自定义视图
    View inflate = LayoutInflater.from(context).inflate(R.layout.dialog_staff_task_info, null);
    task_name = inflate.findViewById(R.id.task_name);
    task_desc = inflate.findViewById(R.id.task_desc);
    taskNum = inflate.findViewById(R.id.task_number);
    taskType = inflate.findViewById(R.id.task_type);
    taskLevel = inflate.findViewById(R.id.task_level);
    taskPerson = inflate.findViewById(R.id.task_person);
    taskStatue = inflate.findViewById(R.id.task_statue);
    taskTime = inflate.findViewById(R.id.task_time);

    setContentView(inflate);
    //是否可取消
    setCancelable(true);
    setCanceledOnTouchOutside(true);
    //去除外围的灰色遮罩
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

    //设置初始显示高度
    BottomSheetBehavior<View> from = BottomSheetBehavior.from((View) inflate.getParent());
    from.setPeekHeight(SizeUtils.dp2px(300));

    //设置拨号按钮事件

  }

  public void show(String name, String desc) {
    task_name.setText(name);

    if (TextUtils.isEmpty(desc)) {
      task_desc.setVisibility(View.GONE);
    }
    else {
      task_desc.setVisibility(View.VISIBLE);
      task_desc.setText(desc);
    }

    show();
  }

  public void show(TaskDetailsInfoEntity.TaskBaseInfoVoBean taskBaseInfoVo) {
    task_name.setText(taskBaseInfoVo.getTaskName());

    if (TextUtils.isEmpty(taskBaseInfoVo.getTaskContents())) {
      task_desc.setVisibility(View.GONE);
    }
    else {
      task_desc.setVisibility(View.VISIBLE);
      task_desc.setText(taskBaseInfoVo.getTaskContents());
    }
    taskNum.setText(taskBaseInfoVo.getTaskNumber()+"");
    taskType.setText(taskBaseInfoVo.getTaskType()+"");
    if("1".equals(taskBaseInfoVo.getTaskDegree())){
      taskLevel.setText("普通");
    }else{
      taskLevel.setText("紧急");
    }

    if(TextUtils.isEmpty(taskBaseInfoVo.getTaskToIds()) || "null".equals(taskBaseInfoVo.getTaskToIds())){
      taskPerson.setText("");
    }else{
      taskPerson.setText(taskBaseInfoVo.getTaskToIds());
    }
//    taskPerson.setText(taskBaseInfoVo.);
    if(TextUtils.isEmpty(taskBaseInfoVo.getTaskFromStatus()) || "null".equals(taskBaseInfoVo.getTaskFromStatus())){
      taskStatue.setText("");
    }else {
      showStatue(taskBaseInfoVo.getTaskFromStatus(), taskStatue);
    }
    taskTime.setText(taskBaseInfoVo.getBeginTime());

    show();
  }

  private void showStatue(String id, TextView tv_status){

      if (id.equals(Constants.TASK_UNACCEPT_TYPE + "")) {
        tv_status.setText("未接收");
//        tv_status.setBackgroundResource(R.drawable.shape_task_unaccept_status_bg_bg);
      } else if (id.equals(Constants.TASK_FINISH_TYPE + "")) {
        tv_status.setText("已执行");
//        tv_status.setBackgroundResource(R.drawable.shape_task_finish_status_bg_bg);
      } else if (id.equals(Constants.TASK_ACTION_TYPE + "")) {
        tv_status.setText("已接收");
//        tv_status.setBackgroundResource(R.drawable.shape_task_accept_status_bg_bg);
      } else if (id.equals(Constants.TASK_CHECK_PASS + "")) {
        tv_status.setText("审核通过");
//        tv_status.setBackgroundResource(R.drawable.shape_task_accept_status_bg_bg);
      }

  }
}

